package com.example.ccjml;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.annotation.Nullable;

import com.example.ccj.b.a.BaseActivity;
import com.example.ccj.b.c.custom.IMRadioButtonListener;
import com.example.ccj.b.c.custom.MButton;
import com.example.ccj.b.c.custom.MRadioButton;
import com.example.ccj.b.c.custom.OptionChoiceControl;
import com.example.ccj.b.c.custom.adapter.OptionChoiceRecyclerAdapter;
import com.example.ccj.b.c.custom.adapter.OptionMode;
import com.example.ccj.b.c.recycler.BaseRecycler;
import com.example.ccj.u.LogUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class TestOptionChoiceControl extends BaseActivity {

    BaseRecycler<String> danXuan;
    BaseRecycler<String> duoXuan;
    OptionChoiceControl<testOption> optionChoiceControl;
    MButton mButton;

    @Override
    public void initData(@Nullable Bundle bundle) {
        List<testOption>  optionDan = new ArrayList<>();
        optionDan.add(new testOption(false,"测试111111111"));
        optionDan.add(new testOption(false,"测试22222222"));
        optionDan.add(new testOption(false,"测试333333"));
        optionDan.add(new testOption(true,"测试4444444444"));

        optionChoiceControl.setCheck(true);
        optionChoiceControl.setMode(MRadioButton.MULTIPLE);
        optionChoiceControl.setList(optionDan).setSelectListener(new IMRadioButtonListener<testOption>() {
            @Override
            public CharSequence getOptionText(testOption testOption) {
                return testOption.text;
            }

            @Override
            public CharSequence getTag(testOption testOption) {
                return null;
            }

            @Override
            public boolean checkIsCorrect(testOption testOption) {
                return testOption.isRight;
            }

            @Override
            public void onCheckedChanged(MRadioButton<testOption> radioButton, boolean isChecked) {
                LogUtils.d(optionChoiceControl.getSelectedData());
            }
        }).build();

        mButton.setOnClickListener(v-> optionChoiceControl.check(true));

    }

    @Override
    public void doBusiness() {

    }

    @Override
    public void initView(@Nullable Bundle savedInstanceState, @Nullable View contentView) {
        danXuan = findViewById(R.id.activity_test_option_choice_control_option_single);
        duoXuan = findViewById(R.id.activity_test_option_choice_control_option_duo);
        optionChoiceControl = findViewById(R.id.activity_test_m_option_option_choice_control);
        mButton = findViewById(R.id.activity_test_m_option_submit);
    }

    @Override
    public int initContentView() {
        return R.layout.activity_test_option_choice_control;
    }


    class testOption{

        public testOption(boolean isRight,String text){
            this.isRight = isRight;
            this.text = text;
        }

        public boolean isRight;
        public String text;


        @Override
        public String toString() {
            return "testOption{" +
                    "isRight=" + isRight +
                    ", text='" + text + '\'' +
                    '}';
        }
    }

}